home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 3 / CD ACTUAL 3.iso / linux / system / flicb_1.6 / flicb_1 / flicb / history.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-08  |  1.9 KB  |  98 lines

  1. /* Copyright (c) 1990 by Carrick Sean Casey. */
  2. /* For copying and distribution information, see the file COPYING. */
  3.  
  4. /* Modified by Mark Giaquinto for International CB, Copyright (C) 1991 */
  5. /* Slightly modified by Mark Luljak for FLICB */
  6.  
  7. #include "flicb.h"
  8. #define HISTMAX 10
  9.  
  10. /* message history routines */
  11.  
  12. STRLIST *histhead, *histtail;    /* head and tail of history list */
  13.  
  14. int histnum = 0;        /* current number of history entries */
  15.  
  16. STRLIST *hp;            /* user current location in history list */
  17.  
  18.  
  19. /* add a username to the list */
  20. /* called whenever a user sends a personal message to another */
  21.  
  22. histput(nick)
  23. char *nick;
  24. {
  25.     char *malloc();
  26.     STRLIST *sp;
  27.  
  28.     /* hunt for user within list */
  29.     for (sp = histhead; sp; sp = sp->next)
  30.         if (!strcasecmp(nick, sp->str)) {
  31.             /* found user -- put at head of list */
  32.             strunlink(sp, &histhead, &histtail);
  33.             strlinkhead(sp, &histhead, &histtail);
  34.             hp = histhead;
  35.             return;
  36.         }
  37.  
  38.     /* user wasn't found */
  39.     if (histnum < HISTMAX) {
  40.         /* make a new entry for the user */
  41.         if ((sp = (STRLIST *) malloc (sizeof(STRLIST) + strlen(nick))) == NULL) {
  42.             return;
  43.         }
  44.         strcpy(sp->str, nick);
  45.         strlinkhead(sp, &histhead, &histtail);
  46.         histnum++;
  47.     } else {
  48.         /* history list full, link user to head, remove tail */
  49.         sp = histtail;
  50.         strunlink(sp, &histhead, &histtail);
  51.         free(sp);
  52.         histnum--;
  53.         if ((sp = (STRLIST *)
  54.          malloc (sizeof(STRLIST) + strlen(nick))) == NULL) {
  55.             return;
  56.         }
  57.         strcpy(sp->str, nick);
  58.         strlinkhead(sp, &histhead, &histtail);
  59.         histnum++;
  60.     }
  61.     hp = histhead;
  62. }
  63.  
  64. /* return a history entry */
  65. /* repeatedly called, will cycle through history entries */
  66.  
  67. char *
  68. histget()
  69. {
  70.     STRLIST *p = hp;
  71.  
  72.     hp = hp->next;
  73.     if (hp == 0)
  74.         hp = histhead;
  75.     return(p->str);
  76. }
  77.     
  78.  
  79. /* return number of names in current history list */
  80.  
  81. histcount()
  82. {
  83.     return(histnum);
  84. }
  85.  
  86. histclear()
  87. {
  88.     STRLIST *tmp, *p = hp;
  89.  
  90.     while (p) {
  91.         tmp = p->next;
  92.         free(p);
  93.         p = tmp;
  94.     }
  95.     histnum = 0;
  96.     hp = histhead = histtail = 0;
  97. }
  98.